import { AuthType } from '@/store/reducers/user';

export const TOKEN_KEY = 'geek-park-mobile';

/** 获取token */
export const getToken = (): AuthType => {
  return JSON.parse(localStorage.getItem(TOKEN_KEY) || '{}');
};

/** 存储token */
export const setToken = (auth: AuthType): void => {
  localStorage.setItem(TOKEN_KEY, JSON.stringify(auth));
};

/** 清空token */
export const clearToken = (): void => {
  localStorage.removeItem(TOKEN_KEY);
};

/** 有无token */
export const hasToken = (): boolean => {
  return !!getToken().token;
};
